home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / Bgui / include / bgui / bgui_treeview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-09  |  11.9 KB  |  399 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/gadgets/TreeView/include/TreeViewClass.h,v 41.11 2000/05/09 20:36:14 mlemos Exp $
  3.  *
  4.  * BGUI Tree List View class
  5.  *
  6.  * (C) Copyright 1999 Manuel Lemos.
  7.  * (C) Copyright 1996-1999 Nick Christie.
  8.  * All Rights Reserved.
  9.  *
  10.  * $Log: TreeViewClass.h,v $
  11.  * Revision 41.11  2000/05/09 20:36:14  mlemos
  12.  * Bumped to revision 41.11
  13.  *
  14.  * Revision 1.2  2000/05/09 20:01:08  mlemos
  15.  * Merged with the branch Manuel_Lemos_fixes.
  16.  *
  17.  * Revision 1.1.2.1  1999/02/21 04:08:33  mlemos
  18.  * Nick Christie sources.
  19.  *
  20.  *
  21.  *
  22.  */
  23.  
  24. /************************************************************************
  25. ***************************  TREEVIEW CLASS  ****************************
  26. *************************************************************************
  27. *
  28. * NAME
  29. *
  30. * Class:        treeviewclass [private]
  31. * SuperClass:    groupclass [BGUI, public]
  32. *
  33. *
  34. * FUNCTION
  35. *
  36. * This is a BGUI gadget class that can display data with a hierarchical
  37. * or tree-like structure. In general appearance, it looks like a BGUI
  38. * listview, in fact, it currently uses a listview for basic control
  39. * and display purposes.
  40. *
  41. * The name of each member of the tree is displayed appropriately indented,
  42. * with a small box next to it containing a plus sign if the children of
  43. * the member have been expanded, a minus sign if not. By clicking on the
  44. * box, the user can expand or contract the child list.
  45. *
  46. * Like the BGUI listview, the treeview's native datatype for its
  47. * members is a C-style string. However, hooks are provided to allow
  48. * any type of data to be added to the tree.
  49. *
  50. *
  51. * NEW METHODS
  52. *
  53. *
  54. *
  55. * CHANGED METHODS
  56. *
  57. *
  58. *
  59. * ATTRIBUTES
  60. *
  61. * TV_??? -- (ULONG)                (ISG--)
  62. *
  63. *
  64. *
  65. * EXTERNAL REQUIREMENTS
  66. *
  67. * Client must open these libraries: intuition.library V37+,
  68. * utility.library V37+ and bgui.library V40+ and provide their
  69. * base pointers.
  70. *
  71. *
  72. *************************************************************************/
  73.  
  74. /************************************************************************
  75. *************************  PUBLIC DEFINITIONS  **************************
  76. ************************************************************************/
  77.  
  78. /*
  79.  * Tags for class attributes
  80.  */
  81.  
  82. #define TAG_TVA_BASE        TAG_USER+0x12340000
  83.  
  84. #define TVA_ResourceHook    (TAG_TVA_BASE+1)    /* (I----) */
  85. #define TVA_DisplayHook        (TAG_TVA_BASE+2)    /* (I----) */
  86. #define TVA_CompareHook        (TAG_TVA_BASE+3)    /* (I----) */
  87. #define TVA_ExpandHook        (TAG_TVA_BASE+4)    /* (I----) */
  88. #define TVA_ImageStyle        (TAG_TVA_BASE+5)    /* (I----) */
  89. #define TVA_LineStyle        (TAG_TVA_BASE+6)    /* (I----) */
  90. #define TVA_ExpandedImage    (TAG_TVA_BASE+7)    /* (I----) */
  91. #define TVA_ContractedImage    (TAG_TVA_BASE+8)    /* (I----) */
  92. #define TVA_LeftAlignImage    (TAG_TVA_BASE+9)    /* (I----) */
  93. #define TVA_NoLeafImage        (TAG_TVA_BASE+10)    /* (I----) */
  94. #define TVA_CopyEntries        (TAG_TVA_BASE+11)    /* (I----) */
  95. #define TVA_Entry            (TAG_TVA_BASE+20)    /* (---N-) */
  96. #define TVA_Parent            (TAG_TVA_BASE+21)    /* (---N-) */
  97. #define TVA_Moved            (TAG_TVA_BASE+22)    /* (---N-) */
  98. #define TVA_NumEntries        (TAG_TVA_BASE+30)    /* (--G--) */
  99. #define TVA_LastClicked        (TAG_TVA_BASE+31)    /* (--G--) */
  100. #define TVA_ViewBounds        (TAG_TVA_BASE+32)    /* (--G--) */
  101. #define TVA_Indentation        (TAG_TVA_BASE+40)    /* (ISG--) */
  102. #define TVA_Top                (TAG_TVA_BASE+41)    /* (-SG--) */
  103.  
  104. /*
  105.  * Tags for class methods
  106.  */
  107.  
  108. #define TAG_TVM_BASE        TAG_TVA_BASE+512
  109.  
  110. #define TVM_INSERT            (TAG_TVM_BASE+1)
  111. #define TVM_REMOVE            (TAG_TVM_BASE+2)
  112. #define TVM_REPLACE            (TAG_TVM_BASE+3)
  113. #define TVM_MOVE            (TAG_TVM_BASE+4)
  114. #define TVM_GETENTRY        (TAG_TVM_BASE+5)
  115. #define TVM_SELECT            (TAG_TVM_BASE+6)
  116. #define TVM_VISIBLE            (TAG_TVM_BASE+7)
  117. #define TVM_EXPAND            (TAG_TVM_BASE+8)
  118. #define TVM_CLEAR            (TAG_TVM_BASE+9)
  119. #define TVM_LOCK            (TAG_TVM_BASE+10)
  120. #define TVM_UNLOCK            (TAG_TVM_BASE+11)
  121. #define TVM_SORT            (TAG_TVM_BASE+12)
  122. #define TVM_REDRAW            (TAG_TVM_BASE+13)
  123. #define TVM_REFRESH            (TAG_TVM_BASE+14)
  124. #define TVM_REBUILD            (TAG_TVM_BASE+15)        /* debug only! */
  125.  
  126. /*
  127.  * Values for TVA_ImageStyle:
  128.  */
  129.  
  130. #define TVIS_BOX            0
  131. #define TVIS_ARROW            1
  132.  
  133. /*
  134.  * Values for TVA_LineStyle:
  135.  */
  136.  
  137. #define TVLS_NONE            0
  138. #define TVLS_DOTS            1
  139. #define TVLS_DASH            2
  140. #define TVLS_SOLID            3
  141.  
  142. /*
  143.  * Message structure for TVM_INSERT, TVM_MOVE:
  144.  */
  145.  
  146. struct tvInsert {
  147.     ULONG                tvi_MethodID;    /* TVM_INSERT, TVM_MOVE */
  148.     struct GadgetInfo    *tvi_GInfo;        /* GadgetInfo */
  149.     APTR                tvi_Entry;        /* entry to insert or move */
  150.     APTR                tvi_Relation;    /* parent or sibling entry */
  151.     ULONG                tvi_Where;        /* see below */
  152.     ULONG                tvi_Flags;        /* see below */
  153. };
  154.  
  155. /*
  156.  * Message structure for TVM_REPLACE
  157.  */
  158.  
  159. struct tvReplace {
  160.     ULONG                tvr_MethodID;    /* TVM_REPLACE */
  161.     struct GadgetInfo    *tvr_GInfo;        /* GadgetInfo */
  162.     APTR                tvr_NewEntry;    /* entry to replace with */
  163.     APTR                tvr_OldEntry;    /* entry to replace */
  164.     ULONG                tvr_Where;        /* see below */
  165.     ULONG                tvr_Flags;        /* see below */
  166. };
  167.  
  168. /*
  169.  * Message structure for TVM_GETENTRY:
  170.  */
  171.  
  172. struct tvGet {
  173.     ULONG                tvg_MethodID;    /* TVM_GET */
  174.     APTR                tvg_Entry;        /* parent or sibling, etc */
  175.     ULONG                tvg_Which;        /* see below */
  176.     ULONG                tvg_Flags;        /* see below */
  177. };
  178.  
  179. /*
  180.  * Message structure for TVM_REMOVE, TVM_SELECT,
  181.  * TVM_VISIBLE, TVM_EXPAND:
  182.  */
  183.  
  184. struct tvEntry {
  185.     ULONG                tve_MethodID;    /* TVM_REMOVE, etc */
  186.     struct GadgetInfo    *tve_GInfo;        /* GadgetInfo */
  187.     APTR                tve_Entry;        /* entry, parent or sibling, etc */
  188.     ULONG                tve_Which;        /* see below */
  189.     ULONG                tve_Flags;        /* see below */
  190. };
  191.  
  192. /*
  193.  * Message structure for TVM_LOCK consists of only the MethodID.
  194.  */
  195.  
  196. /*
  197.  * Message structure for TVM_SORT, TVM_REDRAW, TVM_REFRESH,
  198.  * TVM_CLEAR and TVM_UNLOCK:
  199.  */
  200.  
  201. struct tvCommand {
  202.     ULONG                tvc_MethodID;    /* method ID value */
  203.     struct GadgetInfo    *tvc_GInfo;        /* GadgetInfo */
  204. };
  205.  
  206. /*
  207.  * Special values for any pointer to an existing entry:
  208.  */
  209.  
  210. #define TV_ROOT            ((APTR) 0L)        /* dummy root entry */
  211. #define TV_SELECTED        ((APTR) 1L)        /* first selected entry */
  212.  
  213. /*
  214.  * For internal use only
  215.  */
  216.  
  217. #define TVWC_ENTRY            (0L<<16)
  218. #define TVWC_PARENT            (1L<<16)
  219. #define TVWC_CHILD            (2L<<16)
  220. #define TVWC_SIB            (3L<<16)
  221. #define TVWC_TREE            (4L<<16)
  222. #define TVWC_MASK            (7L<<16)
  223.  
  224. #define TVWS_FIRST            1
  225. #define TVWS_LAST            2
  226. #define TVWS_NEXT            3
  227. #define TVWS_PREV            4
  228. #define TVWS_PGUP            5
  229. #define TVWS_PGDN            6
  230. #define TVWS_SORT            7
  231. #define TVWS_ALL            8
  232. #define TVWS_TREE            9
  233. #define TVWS_MASK            15
  234.  
  235. /*
  236.  * Values for tv?_Which and tv?_Where:
  237.  *
  238.  * Key: I = insert, R = remove, P = replace, M = move, G = get,
  239.  *        S = select, V = visible, E = expand
  240.  */
  241.  
  242. #define TVW_ENTRY            (TVWC_ENTRY)            /* specified entry only (R,P,G,S,V,E) */
  243. #define TVW_PARENT            (TVWC_PARENT)            /* parent of entry (R,P,G,S,V,E) */
  244. #define TVW_CHILD_FIRST        (TVWC_CHILD|TVWS_FIRST)    /* first child of entry (I,R,P,M,G,S,V,E) */
  245. #define TVW_CHILD_LAST        (TVWC_CHILD|TVWS_LAST)    /* last child of entry (I,R,P,M,G,S,V,E) */
  246. #define TVW_CHILD_SORTED    (TVWC_CHILD|TVWS_SORT)    /* child of entry, sorted (I,P,M) */
  247. #define TVW_CHILD_ALL        (TVWC_CHILD|TVWS_ALL)    /* all children of entry (R,P,S,E) */
  248. #define TVW_CHILD_TREE        (TVWC_CHILD|TVWS_TREE)    /* all children, recursively (S,E) */
  249. #define TVW_SIBLING_FIRST    (TVWC_SIB|TVWS_FIRST)    /* first sibling of entry (I,R,P,M,G,S,V,E) */
  250. #define TVW_SIBLING_LAST    (TVWC_SIB|TVWS_LAST)    /* last sibling of entry (I,R,P,M,G,S,V,E) */
  251. #define TVW_SIBLING_NEXT    (TVWC_SIB|TVWS_NEXT)    /* next sibling of entry (I,R,P,M,G,S,V,E) */
  252. #define TVW_SIBLING_PREV    (TVWC_SIB|TVWS_PREV)    /* prev. sibling of entry (I,R,P,M,G,S,V,E) */
  253. #define TVW_SIBLING_SORTED    (TVWC_SIB|TVWS_SORT)    /* sibling of entry, sorted (I,P,M) */
  254. #define TVW_SIBLING_ALL        (TVWC_SIB|TVWS_ALL)        /* entry and all siblings (R,P,S,E) */
  255. #define TVW_SIBLING_TREE    (TVWC_SIB|TVWS_TREE)    /* entry, siblings and all children recursively (S,E) */
  256. #define TVW_TREE_FIRST        (TVWC_TREE|TVWS_FIRST)    /* first in tree, entry ignored (R,G,S,V,E) */
  257. #define TVW_TREE_LAST        (TVWC_TREE|TVWS_LAST)    /* last in tree, entry ignored (R,G,S,V,E) */
  258. #define TVW_TREE_NEXT        (TVWC_TREE|TVWS_NEXT)    /* next in tree from entry (R,G,S,V,E) */
  259. #define TVW_TREE_PREV        (TVWC_TREE|TVWS_PREV)    /* prev. in tree from entry (R,G,S,V,E) */
  260. #define TVW_TREE_PAGE_UP    (TVWC_TREE|TVWS_PGDN)    /* page up in tree from entry (G,S,V,E) */
  261. #define TVW_TREE_PAGE_DOWN    (TVWC_TREE|TVWS_PGUP)    /* page down in tree from entry (G,S,V,E) */
  262.  
  263. /*
  264.  * Bits for tv?_Flags:
  265.  */
  266.  
  267. #define TVF_ALL                0L            /* dummy flag for all entries */
  268. #define TVF_SELECTED        (1L<<0)        /* affect only selected entries (R,P,G,V,E) */
  269. #define TVF_VISIBLE            (1L<<1)        /* affect only visible entries (R,P,G,E) */
  270.  
  271. #define TVF_SELECT            (1L<<8)        /* select entry (I,P,M,V,E) */
  272. #define TVF_DESELECT        (1L<<9)        /* deselect entry (P,M,S,V,E) */
  273. #define TVF_MULTISELECT        (1L<<10)    /* multi-select entry (with TVF_SELECT) */
  274. #define TVF_MAKEVISIBLE        (1L<<11)    /* make entry visible (I,P,M,S,E) */
  275. #define TVF_EXPAND            (1L<<12)    /* expand entry (I,P,M,S,V) */
  276. #define TVF_CONTRACT        (1L<<13)    /* contract entry (P,M,S,V,E) */
  277. #define TVF_TOGGLE            (1L<<14)    /* toggle selection/expansion (S,E) */
  278.  
  279. #define TVF_USER_ACTION        (1L<<30)    /* private */
  280. #define TVF_INTERNAL        (1L<<31)    /* private */
  281.  
  282. /*
  283.  * The TV_ResourceHook is called as follows:
  284.  *
  285.  * rc = hookFunc( REG(A0) struct Hook *hook,
  286.  *                  REG(A2) Object *tv_object,
  287.  *                  REG(A1) struct tvResource *message );
  288.  *
  289.  * On make, return a pointer to the entry to be added, or NULL.
  290.  * On kill, return 0.
  291.  */
  292.  
  293. struct tvResource {
  294.     UWORD            tvr_Command;        /* whether to make or kill */
  295.     APTR            tvr_Entry;            /* entry to be added or removed */
  296. };
  297.  
  298. /*
  299.  * TV_ResourceHook commands in tvr_Command
  300.  */
  301.  
  302. #define TVRC_MAKE        1                /* Build the entry. */
  303. #define TVRC_KILL        2                /* Kill the entry.  */
  304.  
  305. /*
  306.  * The TV_DisplayHook is called as follows:
  307.  *
  308.  * rc = hookFunc( REG(A0) struct Hook *hook,
  309.  *                  REG(A2) Object *tv_object,
  310.  *                  REG(A1) struct tvRender *message );
  311.  *
  312.  * If your hook completes all rendering, return 0. If you wish
  313.  * the treeview to render a string, return the string, which
  314.  * may have BGUI-style formatting sequences embedded in it.
  315.  */
  316.  
  317. struct tvRender {
  318.     struct RastPort *tvr_RPort;            /* rastport to render in */
  319.     struct DrawInfo *tvr_DrawInfo;        /* all you need to render */
  320.     struct Rectangle tvr_Bounds;        /* bounds to render in */
  321.     APTR            tvr_Entry;            /* entry to render */
  322.     UWORD            tvr_State;            /* see below */
  323.     UWORD            tvr_Flags;            /* see below */
  324. };
  325.  
  326. /*
  327.  * Rendering states in lvr_State
  328.  */
  329.  
  330. #define TVRS_NORMAL                0        /* normal, enabled state */
  331. #define TVRS_SELECTED            1        /* selected and enabled */
  332. #define TVRS_NORMAL_DISABLED    2        /* normal disabled state */
  333. #define TVRS_SELECTED_DISABLED    3        /* selected and disabled */
  334.  
  335. /*
  336.  * Flag bits in lvr_Flags
  337.  */
  338.  
  339. #define TVRF_EXPANDED        (1L<<0)        /* entry is expanded */
  340.  
  341. /*
  342.  * The TV_CompareHook is called as follows:
  343.  *
  344.  * rc = hookFunc( REG(A0) struct Hook *hook,
  345.  *                  REG(A2) Object *tv_object,
  346.  *                  REG(A1) struct tvCompare *message );
  347.  *
  348.  * Your hook must return -1 when entry A should come before entry B, 0 when
  349.  * entry A is equal to entry B and 1 when entry A should come after entry B.
  350.  */
  351.  
  352. struct tvCompare {
  353.     APTR            tvc_EntryA;            /* first entry */
  354.     APTR            tvc_EntryB;            /* second entry */
  355. };
  356.  
  357. /*
  358.  * The TV_ExpandHook is called as follows:
  359.  *
  360.  * rc = hookFunc( REG(A0) struct Hook *hook,
  361.  *                  REG(A2) Object *tv_object,
  362.  *                  REG(A1) struct tvExpand *message );
  363.  *
  364.  * Your hook should return non-zero if the expansion or contraction
  365.  * is to go ahead, zero if it should be cancelled.
  366.  *
  367.  * Important: Your hook may *not* invoke any methods on the treeview.
  368.  */
  369.  
  370. struct tvExpand {
  371.     UWORD            tve_Command;        /* whether to expand or contract */
  372.     APTR            tve_Entry;            /* entry to be expanded/contracted */
  373.     ULONG            tve_Flags;            /* see below */
  374. };
  375.  
  376. /*
  377.  * tvExpand commands in tve_Command
  378.  */
  379.  
  380. #define TVEC_EXPAND            1            /* entry is to be expanded */
  381. #define TVEC_CONTRACT        2            /* entry is to be contracted */
  382.  
  383. /*
  384.  * Flag bits in tve_Flags
  385.  */
  386.  
  387. #define TVEF_USER_ACTION    (1L<<0)        /* hook called due to user action */
  388.  
  389. /************************************************************************
  390. **************************  PUBLIC PROTOTYPES  **************************
  391. ************************************************************************/
  392.  
  393. Class *MakeTreeViewClass(void);
  394.  
  395. BOOL FreeTreeViewClass(Class *cl);
  396.  
  397.  
  398.